package pro.spring.service;

import java.util.Date;
import java.util.Random;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import pro.spring.inter.ImagesMapper;
import pro.spring.model.Images;
import pro.spring.vo.PaginationVo;

@Service
public class ImagesService{

	@Autowired
	private ImagesMapper ImagesMapper;
	
	public int deleteByPrimaryKey(Integer id) {
		return ImagesMapper.deleteByPrimaryKey(id);
	}

	public int insert(Images record) {
		return ImagesMapper.insert(record);
	}

	public Images selectByPrimaryKey(Integer id) {
		return ImagesMapper.selectByPrimaryKey(id);
	}

	public int updateByPrimaryKey(Images record) {
		return ImagesMapper.updateByPrimaryKey(record);
	}
	
	public int selectCountNewId() {
		return ImagesMapper.selectCountNewId();
	}
	
	public PaginationVo<Images> getPaginationInfo(int pagenum,int pagesize){
		//int pagenum是当前的页码,int pagesize是每页显示的数据数量
		PaginationVo<Images> pageVo=new PaginationVo<Images>();
		//一定要在setPageCount()方法之后执行setPageNum
		pageVo.setCount(ImagesMapper.selectCount());
		pageVo.setRows(pagesize);
		pageVo.setPageNum(pagenum);
		pageVo.setList(ImagesMapper.selectListPage(pageVo.getOffset(), pageVo.getRows()));
		return pageVo;
	}
	
	public String getImageName(){
		String name = null ;
		Random r = new Random();
		String a = String.valueOf(r.nextInt(999999));
		String time = String.valueOf(new Date().getTime());
		name = a+time;
		return name;
	}
	
}
